import request from '@/utils/request'

/**
 * 普通文件上传
 */
export function uploadFile(formData) {
  return request({
    url: '/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 分片上传
 */
export function uploadChunk(formData) {
  return request({
    url: '/file/upload/chunk',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 合并分片
 */
export function mergeChunks(data) {
  return request({
    url: '/file/upload/merge',
    method: 'post',
    params: data
  })
}

/**
 * 检查已上传的分片
 */
export function checkUploadedChunks(md5) {
  return request({
    url: '/file/upload/check-chunks',
    method: 'get',
    params: { md5 }
  })
}

/**
 * 检查文件是否存在
 */
export function checkFile(md5) {
  return request({
    url: '/file/check',
    method: 'get',
    params: { md5 }
  })
}

/**
 * 获取文件分页列表
 */
export function getFilePage(params) {
  return request({
    url: '/file/page',
    method: 'get',
    params
  })
}

/**
 * 删除文件
 */
export function deleteFile(id) {
  return request({
    url: `/file/${id}`,
    method: 'delete'
  })
}
